home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / locale.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.1 KB  |  222 lines

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.3; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.3
  10. date    97.09.17.08.16.17;    author dlorre;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    97.07.14.04.20.40;    author dlorre;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Oui.lib -- Object User Interface
  27. Projet créé en 1994
  28. Auteur: Dominique Lorre
  29. @
  30.  
  31.  
  32. 1.3
  33. log
  34. @*** empty log message ***
  35. @
  36. text
  37. @// $Id: locale.cc 1.2 1997/07/14 04:20:40 dlorre Exp dlorre $
  38. #include <exec/types.h>
  39. #include <dos/dos.h>
  40. #include "locale.h"
  41.  
  42. #if defined( LOCALISE )
  43. #include <stdio.h>
  44. #include <string.h>
  45. #endif
  46.  
  47. #if defined( LOCALISE )
  48. #include <proto/dos.h>
  49. #endif
  50. #include <proto/locale.h>
  51. #include <mydebug.h>
  52.  
  53. #if defined( LOCALISE )
  54. static char ch[255] ;
  55. static char cdfilename[255] ;
  56. static char ctfilename[255] ;
  57. static BPTR fh ;
  58.  
  59. static void AppendString(STRPTR def, STRPTR string, int id, STRPTR desc, catalog *lc)
  60. {
  61. int l ;
  62.     sprintf(ch, lc->catname) ;
  63.     l = strlen(ch) ;
  64.     if (l > 8 && !strcmp(ch+l-8, ".catalog")) {
  65.         ch[l-8] = '\0' ;
  66.     }
  67.     sprintf(cdfilename, "RAM:%s.cd", ch) ;
  68.     sprintf(ctfilename, "RAM:%s_%s.ct", ch, lc->langname) ;
  69.  
  70.     if (fh = Open(cdfilename, MODE_READWRITE)) {
  71.         if (Seek(fh, 0, OFFSET_END) != -1) {
  72.             if (id != -1)
  73.                 sprintf(ch, "%s (%ld//)\n%s\n", desc, id, def) ;
  74.             else
  75.                 sprintf(ch, "%s (//)\n%s\n", desc, def) ;
  76.             Write(fh, ch, strlen(ch)) ;
  77.             Flush(fh) ;
  78.         }
  79.         Close(fh) ;
  80.     }
  81.     if (fh = Open(ctfilename, MODE_READWRITE)) {
  82.         if (Seek(fh, 0, OFFSET_END) != -1) {
  83.             sprintf(ch, "%s\n%s\n;%s\n;\n", desc, string, def) ;
  84.             Write(fh, ch, strlen(ch)) ;
  85.             Flush(fh) ;
  86.         }
  87.         Close(fh) ;
  88.     }
  89. }
  90. #endif
  91.  
  92.  
  93. catalog::catalog(char *name, char *deflang, char *lang) : locnum(0)
  94. {
  95.     if (LocaleBase) {
  96. #if defined( LOCALISE )
  97. int l ;
  98.     strcpy(catname, name) ;
  99.     strcpy(langname, lang ? lang : "default") ;
  100.     sprintf(ch, catname) ;
  101.     l = strlen(ch) ;
  102.     if (l > 8 && !strcmp(ch+l-8, ".catalog")) {
  103.         ch[l-8] = '\0' ;
  104.     }
  105.     sprintf(cdfilename, "RAM:%s.cd", ch) ;
  106.     sprintf(ctfilename, "RAM:%s_%s.ct", ch, langname) ;
  107.     if (fh = Open(cdfilename, MODE_NEWFILE))
  108.         Close(fh) ;
  109.     if (fh = Open(ctfilename, MODE_NEWFILE))
  110.         Close(fh) ;
  111.  
  112. #endif
  113.         cat = OpenCatalog(NULL, name,
  114.             OC_BuiltInLanguage, deflang,
  115.             OC_Language,        lang,
  116.             TAG_DONE) ;
  117.     }
  118.     else
  119.         cat = NULL ;
  120. }
  121. catalog::~catalog() { if (LocaleBase) CloseCatalog(cat) ; }
  122.  
  123.  
  124. #ifdef LOCALISE
  125. lstring::lstring(catalog *lc, char *def, char *desc, int id)
  126. {
  127.     if (lc && LocaleBase) {
  128.         if (id != -1) lc->locnum  = id ;
  129.         string = GetCatalogStr(lc->cat, lc->locnum, def) ;
  130.         AppendString(def, string, id, desc, lc) ;
  131.         lc->locnum++ ;
  132.     }
  133.     else
  134.         string = def ;
  135. }
  136. #else
  137. lstring::lstring(catalog *lc, char *def, int id)
  138. {
  139.     if (lc && LocaleBase) {
  140.         if (id != -1) lc->locnum  = id ;
  141.         string = GetCatalogStr(lc->cat, lc->locnum, def) ;
  142.         lc->locnum++ ;
  143.     }
  144.     else
  145.         string = def ;
  146. }
  147.  
  148. #endif
  149. @
  150.  
  151.  
  152. 1.2
  153. log
  154. @Now is catcomp compatible
  155. @
  156. text
  157. @d1 1
  158. a1 1
  159. // $Id$
  160. d61 1
  161. d63 13
  162. a75 1
  163.     strcpy(langname, lang) ;
  164. @
  165.  
  166.  
  167. 1.1
  168. log
  169. @Initial revision
  170. @
  171. text
  172. @d1 1
  173. d12 1
  174. a12 1
  175. #include <cxxproto/dos.h>
  176. d14 2
  177. a15 2
  178. #include <cxxproto/locale.h>
  179. #include <cclib/debug_protos.h>
  180. d19 2
  181. a20 3
  182. const STRPTR filename = "RAM:locale.txt" ;
  183. const STRPTR fmt = "%05ld %s\n" ;
  184. static void AppendString(char *def, char *id) ;
  185. d23 1
  186. a23 1
  187. static void AppendString(STRPTR def, int id)
  188. d25 8
  189. d34 1
  190. a34 2
  191.     fh = Open(filename, MODE_READWRITE) ;
  192.     if (fh) {
  193. d36 12
  194. a47 1
  195.             sprintf(ch, fmt,id, def) ;
  196. d59 5
  197. a63 1
  198.     if (LocaleBase)
  199. d68 1
  200. d75 2
  201. a76 2
  202.  
  203. lstring::lstring(catalog *lc, char *def, int id)
  204. d79 4
  205. a82 5
  206.         string = GetCatalogStr(lc->cat, id, def) ;
  207. #if defined( LOCALISE )
  208.         AppendString(string, id) ;
  209. #endif
  210.         lc->locnum = id + 1 ;
  211. d87 2
  212. a88 2
  213.  
  214. lstring::lstring(catalog *lc, char *def)
  215. d91 1
  216. a92 3
  217. #if defined( LOCALISE )
  218.         AppendString(string, lc->locnum) ;
  219. #endif
  220. d99 1
  221. @
  222.